def f(n):
    for i in range(2, n):
        if n % i == 0:
            return False

    return True
cif = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
s = input()
left = []
right = []
a = s.split()
k = ''
if len(a) <= 3 and a[0] in cif and a[1] in cif and a[2] in cif:
    for x in a:
        k += str(cif.index(x))
    k = int(k)
    for c in range(1, k):
        if f(c):
            left.append(c)
    for c in range(k+1, 1500):
        if f(c):
            right.append(c)
    if k - left[-1] < right[0] - k:
        print(left[-1])
    else:
        print(right[0])
else:
    print('Wrong input')
